package com.example.administrator.zhongyichou.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.administrator.zhongyichou.Bean.ChoiceBean;
import com.example.administrator.zhongyichou.R;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * 第三版新加
 * Created by lichenyu on 2017/5/31.
 */

public class ChoiceDialogAdapter extends BaseAdapter {

    private List<ChoiceBean> bean;
    private Context context;

    public ChoiceDialogAdapter(Context context, List<ChoiceBean> bean) {
        this.context = context;
        this.bean = bean;
    }

    @Override
    public int getCount() {
        return bean.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.choice_dialog_list_item, null);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        if (bean.get(position).isSelect) {
            holder.imgConsumer.setImageResource(R.mipmap.selected_s);
        } else {
            holder.imgConsumer.setImageResource(R.mipmap.selected_n);
        }
        holder.txtName.setText(bean.get(position).name);
        return convertView;
    }

    static class ViewHolder {
        @BindView(R.id.img_consumer)
        ImageView imgConsumer;
        @BindView(R.id.txt_name)
        TextView txtName;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
